package com.nfha.algorithm.geo.crossline.main;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.nfha.algorithm.geo.crossline.CrosslineExerciser;
import com.nfha.algorithm.geo.crossline.CrosslineResult;
import com.nfha.algorithm.geo.crossline.GeoLine;
import com.nfha.algorithm.geo.crossline.GeoShipPoint;
import com.nfha.algorithm.util.IoUtil;
import com.nfha.algorithm.util.Logger;

public class CrosslineFileMain {

	
	static Logger logger=Logger.getConsoleLogger();
	
	
private enum Bridge{
		
		
		 横门摊_宝安机场(113.62158,22.53908,113.849822,22.620771)
		;
		
		GeoLine line;
		
		
		Bridge(double start_lon, double start_lat, double end_lon, double end_lat ) {
			
			line=new GeoLine(start_lon, start_lat, end_lon, end_lat);
			
		}
		
		
	}
	
	
	
	   public static List<GeoShipPoint> loadCvs(File csvFile) throws IOException{
		   
		   List<GeoShipPoint> ret=new ArrayList<>();
		   
		   List<String[]> rows=IoUtil.readCsv(csvFile);
		   
		   for(String[] row : rows) {
			   String name="",imo=row[0];
			 double lon=Double.valueOf(row[2]) ,lat=Double.valueOf(row[3]);
			   
			long arrivalAt=Date.parse(row[4]);
			GeoShipPoint point=new GeoShipPoint(name, lon, lat, imo, arrivalAt);
			 ret.add(point);  
			 
		   }
		   
		   return ret;
		   
	   }
	
	
	   public static void main(String[] args) throws Exception {
		   
		   File csvFile=new File(IoUtil.getPwdResource().getPath()+"input/crossline/test0.csv");
		   List<GeoShipPoint> points=loadCvs(csvFile);
		   
		   points=points.stream()
				   .filter(p-> "413477230".equals(p.imo))
				   .collect(Collectors.toList());
		   
		   try(CrosslineExerciser exerciser=new CrosslineExerciser(6);){
			   
			   
			   
			   List<CrosslineResult> rets= exerciser.exec(Bridge.横门摊_宝安机场.line, points);
			   
			   
			   for(CrosslineResult ret : rets) {
		   			logger.debug("穿过",ret);
		   		}
			   
		   }
		   
		   
		   
	   }
	
	
}
